export function drawTrack (canvas, x1, y1, x2, y2, width = 15, color = '#3a3a3a') {
  let line = new fabric.Line([x1, y1, x2, y2], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'track'
  })
  canvas.add(line)
  return line
}

export function drawGuardRail (canvas, x1, y1, x2, y2, width = 15, color = '#3a3a3a') {
  console.log('drawGuardRail')
  let line = new fabric.Line([x1, y1, x2, y2], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'track'
  })
  canvas.add(line)
  return line
}

export function drawTrackSleeper (canvas, x1, y1, x2, y2, width = 30, color = '#3a3a3a', timeValue = 0,sleeperData) {
  let sleeper = new fabric.Line([x1, y1, x2, y2], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'sleeper'
  })
  // 添加文本
  let text = new fabric.Text('' + sleeperData.sleeperNo, {
    left: x1 + width/2,
    top: (y1+y2)/1.1 ,
    fontSize: 12,
    originX: 'center', // 文本居中对齐到指定点
    originY: 'center',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'sleeperText'
  })
  canvas.add(text)
  canvas.add(sleeper)
}

export function drawTrackPointRight (canvas, x1, y1, x2, y2, width = 15, color = '#909090', timeValue = 0) {
  let sleeper = new fabric.Line([x1, y1, x2, y2], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'sleeper'
  })
  let line1 = new fabric.Line([x1, 145, x1+40, 145], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'track'
  })
  let line2 = new fabric.Line([x1, 300, x1+40, 300], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'track'
  })
  // 添加文本
  let text = new fabric.Text('尖轨尖', {
    left: x1 + width/2,
    top: 35 ,
    fontSize: 10,
    originX: 'center', // 文本居中对齐到指定点
    originY: 'center',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'sleeperText'
  })
  canvas.add(line1)
  canvas.add(line2)
  canvas.add(text)
  canvas.add(sleeper)
}

export function drawTrackPointLeft (canvas, x1, y1, x2, y2, width = 15, color = '#909090', timeValue = 0) {
  let sleeper = new fabric.Line([x1, y1, x2, y2], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'sleeper'
  })
  let line1 = new fabric.Line([x1, 145, x1-25, 145], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'track'
  })
  let line2 = new fabric.Line([x1, 300, x1-25, 300], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'track'
  })
  // 添加文本
  let text = new fabric.Text('尖轨尖', {
    left: x1 + width/2,
    top: 35 ,
    fontSize: 10,
    originX: 'center', // 文本居中对齐到指定点
    originY: 'center',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true,
    class: 'sleeperText'
  })
  canvas.add(line1)
  canvas.add(line2)
  canvas.add(text)
  canvas.add(sleeper)
}

export function drawTrackCrossingRightDown(canvas, x1,x2) {
  const offset =Math.abs(x2-x1) * 2
  const offset1 = Math.abs(x2-x1) / 2
  // 创建 Path2D 对象
  const pathData = 'M ' + x1 + ' ' +  '128 A '+ offset + ' ' + offset1 +  ' 0 0 1 ' +  x2 + ' 466'
  const arcPath = new fabric.Path(pathData, {
    fill: 'transparent', // 设置填充颜色为透明
    stroke: '#3A3A3A', // 设置描边颜色
    strokeWidth: 15, // 设置描边宽度
    class: 'sleeperText',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  });
  canvas.add(arcPath);
  // 创建 Path2D 对象
  const pathData2 = 'M ' + x1 + ' ' +  '328 A '+ offset + ' ' + offset1 +  ' 0 0 1 ' +  x2 + ' 666'
  const arcPath2 = new fabric.Path(pathData2, {
    fill: 'transparent', // 设置填充颜色为透明
    stroke: '#3A3A3A', // 设置描边颜色
    strokeWidth: 15, // 设置描边宽度
    class: 'trackCrossing',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  });
  canvas.add(arcPath2);

}

export function drawTrackCrossingLeftUp(canvas, x1,x2) {
  // 创建 Path2D 对象
  // ' -44 A 4500 xxxx为角度 0 0 0 '
  const offset =Math.abs(x2-x1) * 2
  const offset1 = Math.abs(x2-x1) / 2
  console.log('oooo',offset)
  const pathData = 'M ' + x1 + ' -210 A '+ offset + ' ' + offset1 +  ' 0 0 0 ' + x2 + ' 128'
  const arcPath = new fabric.Path(pathData, {
    fill: 'transparent', // 设置填充颜色为透明
    stroke: '#3A3A3A', // 设置描边颜色
    strokeWidth: 15, // 设置描边宽度
    class: 'sleeperText',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  });
  canvas.add(arcPath);

  // 创建 Path2D 对象
  const pathData2 = 'M ' + x1 + ' -10 A '+ offset + ' ' + offset1 +  ' 0 0 0 ' + x2 + ' 328'
  const arcPath2 = new fabric.Path(pathData2, {
    fill: 'transparent', // 设置填充颜色为透明
    stroke: '#3A3A3A', // 设置描边颜色
    strokeWidth: 15, // 设置描边宽度
    class: 'trackCrossing',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  });
  canvas.add(arcPath2);
}

export function drawTrackCrossingLeftDown(canvas, x1,x2) {
  const offset =Math.abs(x2-x1) * 2
  const offset1 = Math.abs(x2-x1) / 2
  // 创建 Path2D 对象
  const pathData = 'M ' + x1 + ' 466 A '+ offset + ' ' + offset1 +  ' 0 0 1 ' + x2 + ' 128'
  const arcPath = new fabric.Path(pathData, {
    fill: 'transparent', // 设置填充颜色为透明
    stroke: '#3A3A3A', // 设置描边颜色
    strokeWidth: 15, // 设置描边宽度
    class: 'sleeperText',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  });
  canvas.add(arcPath);

  // 创建 Path2D 对象
  const pathData2 = 'M ' + x1 + ' 666 A '+ offset + ' ' + offset1 +  ' 0 0 1 ' + x2 + ' 328'
  const arcPath2 = new fabric.Path(pathData2, {
    fill: 'transparent', // 设置填充颜色为透明
    stroke: '#3A3A3A', // 设置描边颜色
    strokeWidth: 15, // 设置描边宽度
    class: 'trackCrossing',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  });
  canvas.add(arcPath2);
}

export function drawTrackCrossingRightUp(canvas, x1,x2) {
  const offset =Math.abs(x2-x1) * 2
  const offset1 = Math.abs(x2-x1) / 2
  // 创建 Path2D 对象
  const pathData = 'M ' + x1 + ' 128 A '+ offset + ' ' + offset1 +  ' 0 0 0 ' + x2 + ' -221'
  const arcPath = new fabric.Path(pathData, {
    fill: 'transparent', // 设置填充颜色为透明
    stroke: '#3A3A3A', // 设置描边颜色
    strokeWidth: 15, // 设置描边宽度
    class: 'sleeperText',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  });
  canvas.add(arcPath);

  // 创建 Path2D 对象
  const pathData2 = 'M ' + x1 + ' 328 A '+ offset + ' ' + offset1 +  ' 0 0 0 ' + x2 + ' -10'
  const arcPath2 = new fabric.Path(pathData2, {
    fill: 'transparent', // 设置填充颜色为透明
    stroke: '#3A3A3A', // 设置描边颜色
    strokeWidth: 15, // 设置描边宽度
    class: 'trackCrossing',
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  });
  canvas.add(arcPath2);
}

export function drawTrackSleeper2 (canvas, x1, y1, x2, y2, width = 30, color = '#3a3a3a', timeValue = 0) {
  let sleeper = new fabric.Line([x1, y1, x2, y2], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  })
  // 添加文本
  let text = new fabric.Text('sleeper' + (timeValue), {
    left: x1 + width + 20,
    top: 250,
    fontSize: 20,
    originX: 'center', // 文本居中对齐到指定点
    originY: 'center',
    angle: -90,
    selection: false,
    selectable: false, // 禁止选择和拖动
    lockMovementX: true,
    lockMovementY: true
  })
  canvas.add(text)
  canvas.add(sleeper)
}
